package musicstore.com.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import musicstore.com.dao.BaseDao;
import musicstore.com.dao.GenreDao;
import musicstore.com.entity.Genre;

public class GenreDaoImpl extends BaseDao implements GenreDao{

	public List<Genre> getGenreList() {
		List<Genre> list = new ArrayList<Genre>();
		String sql="select * from genre where 1 = 1";
		ResultSet rs = null ;
			
		this.openConnection();
		try {
			rs = executeQuery(sql,null);
			while(rs.next()){
				int id=rs.getInt("id");
				String name=rs.getString("name");
				String description=rs.getString("description");
				Genre g = new Genre(id,name,description);
				list.add(g);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			closeResource();
		}
		
		return list;
	}
	
	public static void main(String[] args) {
		List<Genre> list = new GenreDaoImpl().getGenreList();
		for(Genre g : list ){
			System.out.println(g.getId()+"\t"+g.getName());
		}
	}

	
}
